package longrise.phone.com.bjjt_jyb.Adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.longrise.android.LFView;

import java.util.List;

/**
 * Created by Administrator on 2016/5/13.
 */
public class PageAdapter extends PagerAdapter {

    private List<LFView> lists;

    private String[] titles;

    public void setTitles(String[] titles) {
        this.titles = titles;
    }

    public void setLists(List<LFView> lists) {
        this.lists = lists;
    }

    @Override
    public int getCount() {
        if (null == lists) {
            return 0;
        }
        return lists.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        LFView lfView = lists.get(position);
        container.removeView(lfView.getView());
        lfView.OnDestroy();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        LFView lfView = lists.get(position);
        View view = lfView.getView();
        container.addView(view);
        return view;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
